home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 1998 June / SGI IRIX 6.5 Applications 1998 June.iso / dist / arraysvcs.idb / usr / etc / arrayconfig.z / arrayconfig
Text File  |  1998-04-15  |  4KB  |  172 lines

  1. #!/bin/sh
  2. #
  3. # Array configuration script: sets up an arrayd.conf file with an initial
  4. # array, then distributes it to all of the machines in the array and activates
  5. # array services.
  6. #
  7. # Usage: arrayconfig [-a arrayname] [-i] [-m] [-d] host...
  8. #
  9. # Options:
  10. #    -a arrayname: name the array "arrayname"
  11. #    -i: Tune the kernel to use the bottom 15 bits of the current hostid
  12. #        as a permanent machine ID for global ASHs. With "-d", this is
  13. #        done on each machine in the array.
  14. #    -m: Make an arrayd.conf file
  15. #    -d: Distribute the arrayd.conf file across the array and activate
  16. #        array services
  17. #    host...: hostnames of one or more machines that make up the array
  18. #
  19.  
  20. ConfigDir=/usr/lib/array
  21. ConfigFile=$ConfigDir/arrayd.conf
  22. Template=$ConfigDir/arrayd.conf.template
  23. Usage="$0 [-a array] [-m] [-i] [-d] host..."
  24.  
  25. #
  26. # Parse options
  27. #
  28. DoDist=0
  29. DoMachID=0
  30. DoMake=0
  31. Array="default"
  32.  
  33. while getopts "a:dim" CurrOpt; do
  34.     case $CurrOpt in
  35.         a)    Array=$OPTARG;;
  36.         d)    DoDist=1;;
  37.         i)    DoMachID=1;;
  38.         m)    DoMake=1;;
  39.         *)    echo $Usage
  40.             exit 2;
  41.     esac
  42. done
  43. shift `expr $OPTIND - 1`
  44.  
  45.  
  46. #
  47. # Check arguments for sensible-ness
  48. #
  49. if [ $# -lt 1  -a  $DoMachID -eq 0 ]; then
  50.     echo "Must specify at least one host"
  51.     echo $Usage
  52.     exit 2
  53. fi
  54. Hosts=$*
  55.  
  56. if [ $DoMake -eq 0  -a  $DoMachID -eq 0  -a  $DoDist -eq 0 ]; then
  57.     echo "Must specify -d, -i or -m"
  58.     echo $Usage
  59.     exit 2
  60. fi
  61.  
  62.  
  63. #
  64. # Make sure the appropriate directories and files exist and are writable
  65. #
  66. if [ ! -d $ConfigDir ]; then
  67.     echo "Error! Configuration directory $ConfigDir not found"
  68.     exit 2
  69. fi
  70.  
  71. if [ ! -w $ConfigDir ]; then
  72.     echo "Error! Cannot write to $ConfigDir"
  73.     exit 2
  74. fi
  75.  
  76. if [ ! -f $Template  -a  $DoMake -ne 0 ]; then
  77.     echo "Error! Configuration file template $Template not found"
  78.     exit 2;
  79. fi
  80.  
  81.  
  82. #
  83. # Make the config file if desired
  84. #
  85. if [ $DoMake -ne 0 ]; then
  86.  
  87.     #
  88.     # Make sure the configuration file is writable
  89.     #
  90.     if [ -f $ConfigFile ]; then
  91.         echo "Warning: configuration file $ConfigFile already exists"
  92.         if [ -w $ConfigFile ]; then
  93.             echo -n "Overwrite it? (y/n) "
  94.             read Answer
  95.             if [ "$Answer" != "y" ]; then
  96.                 echo "$0 aborting"
  97.                 exit 0;
  98.             fi
  99.         else
  100.             echo "Error! configuration file $ConfigFile is read-only"
  101.             exit 2;
  102.         fi
  103.     fi
  104.  
  105.     #
  106.     # Generate a temporary filename
  107.     #
  108.     TempFile=$ConfigDir/arrayconfig.temporary.$$
  109.     if [ -f $TempFile ]; then
  110.         echo "Temporary file $TempFile already exists! Try again."
  111.         exit 2;
  112.     fi
  113.  
  114.     #
  115.     # Create a temporary file containing the array definition
  116.     #
  117.     echo "array $Array" > $TempFile
  118.     for Host in $Hosts; do
  119.         echo "        machine $Host" >> $TempFile
  120.     done
  121.  
  122.     #
  123.     # Transmogrify the template file
  124.     #
  125.     sed -e "/#-AC1-/r $TempFile"                \
  126.         -e "/#-AC1-/d"                    \
  127.         -e "/#-AC2-/s/.*/        destination array $Array/"    \
  128.         -e "/#-AC3-/d"                    \
  129.         $Template > $ConfigFile
  130.  
  131.     #
  132.     # Don't need the temporary file any longer
  133.     #
  134.     rm $TempFile
  135. fi
  136.  
  137. #
  138. # If we are setting a machine ID but *not* distributing configs,
  139. # do the actual systune
  140. #
  141. if [ $DoMachID -ne 0  -a  $DoDist -eq 0 ]; then
  142.     HostID=`hostid`
  143.     MachID=`perl -e "print $HostID & 0x7fff"`
  144.     echo "asmachid $MachID\ny\nquit" | systune -i > /dev/null 2>&1
  145. fi
  146.  
  147. #
  148. # Distribute the configuration file and activate it if desired
  149. #
  150. if [ $DoDist -ne 0 ]; then
  151.     for Host in $Hosts; do
  152.         rcp $ConfigFile $Host:$ConfigFile
  153.         rsh $Host /sbin/chkconfig array on
  154.         rsh $Host /etc/init.d/array stop
  155.         rsh $Host /etc/init.d/array start > /dev/null
  156.  
  157.         if [ $DoMachID -ne 0 ]; then
  158.             rsh $Host /usr/etc/arrayconfig -i > /dev/null
  159.         fi
  160.     done
  161. fi
  162.  
  163. #
  164. # Print reboot reminder if necessary
  165. #
  166. if [ $DoMachID -ne 0 ]; then
  167.     echo "Reboot system to use new machine ID"
  168. fi
  169.  
  170. echo "Configuration of array $Array complete"
  171. exit 0
  172.